from django.db import models
from db.basemodel import BaseBean
# Create your models here.

# 商品SKU模型
from tinymce.models import HTMLField


class GoodsSKUBean(BaseBean):
    # 商品名称
    name = models.CharField(max_length=20, verbose_name="商品名称")
    # 商品简介
    description = models.CharField(max_length=300, verbose_name="商品简介")
    # 价格
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="商品价格")
    # 单位
    unit = models.CharField(max_length=20, verbose_name="商品单位")
    # 库存量
    surplus = models.IntegerField(default=1, verbose_name="商品库存量")
    # 销量
    sale_count = models.IntegerField(default=0, verbose_name="商品销量")
    # 图片
    image = models.ImageField(upload_to="goods", verbose_name="商品图片")
    # 是否上架状态
    status_choices = (
        (0, "下架"),
        (1, "上架"),
    )
    status = models.SmallIntegerField(default=1, choices=status_choices, verbose_name="商品状态")
    # 种类ID
    kind = models.ForeignKey("GoodsKindBean", verbose_name="商品种类")
    # 商品SPU ID
    goods_spu = models.ForeignKey("GoodsSPUBean", verbose_name="商品SPU")
    # 其他
    class Meta:
        db_table = "table_goods_sku"
        verbose_name = "商品"
        verbose_name_plural = verbose_name

# 商品种类模型
class GoodsKindBean(BaseBean):
    # 种类名称
    name = models.CharField(max_length=20, verbose_name="种类名称")
    # logo小图片
    logo = models.CharField(max_length=20, verbose_name="标识")
    # 分类下的图片
    image = models.ImageField(upload_to="type", verbose_name="商品类型图片")
    class Meta:
        db_table = "table_goods_type"
        verbose_name = "商品种类"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name

# 首页轮播商品模型类
class IndexBannerGoodsBean(BaseBean):
    # 商品SKU ID
    goods_sku = models.ForeignKey("GoodsSKUBean",verbose_name="商品")
    # 图片
    image = models.ImageField(upload_to="banner",verbose_name="图片")
    # 图片位置index
    index = models.SmallIntegerField(default=0,verbose_name="展示顺序")
    class Meta:
        db_table = "table_index_banner_goods"
        verbose_name = "首页轮播商品"
        verbose_name_plural = verbose_name

# 首页促销广告活动商品模型
class IndexActivityBannerGoodsBean(BaseBean):
    # 图片
    image = models.ImageField(upload_to="banner",verbose_name="活动图片")
    # 活动对应的链接url
    activityurl = models.URLField(verbose_name="活动链接")
    # 图片位置index
    index = models.SmallIntegerField(default=0,verbose_name="展示顺序")
    class Meta:
        db_table = "table_index_activity_banner_goods"
        verbose_name = "首页促销广告活动商品"
        verbose_name_plural = verbose_name

# 首页分类商品展示模型
class IndexKindGoodsBannerBean(BaseBean):
    # 商品SKU ID
    goods_sku = models.ForeignKey("GoodsSKUBean",verbose_name="商品SKU")
    # 种类ID
    kind = models.ForeignKey("GoodsKindBean",verbose_name="商品类型")
    # 展示标识值
    display_type_choices = (
        (0,"标题"),
        (1,"图片"),
    )
    display_type = models.SmallIntegerField(default=1,choices=display_type_choices, verbose_name='展示类型')
    # 位置index
    index = models.SmallIntegerField(default=0,verbose_name="展示顺序")
    class Meta:
        db_table = "table_index_kind_banner_goods"
        verbose_name = "首页分类商品展示商品"
        verbose_name_plural = verbose_name

# 商品SPU模型类
class GoodsSPUBean(BaseBean):
    # 商品名称
    name = models.CharField(max_length=20,verbose_name="商品SPU名称")
    # 商品详情
    detail = HTMLField(blank=True,verbose_name="商品详情")
    class Meta:
        db_table = "table_goods_spu"
        verbose_name = "商品SPU"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

# 商品图片模型
class GoodsImageBean(BaseBean):
    # 商品图片
    image = models.ImageField(upload_to="goods",verbose_name="图片路径")
    # 商品SKU ID
    goods_sku = models.ForeignKey("GoodsSKUBean",verbose_name="商品")
    class Meta:
        db_table = "table_goods_image"
        verbose_name = "商品图片"
        verbose_name_plural = verbose_name





